<?php include_once 'header.php'; ?>

<link rel="stylesheet" type="text/css" href="/login/css/styles.css">
<script src="/statics/cz/layer_mobile/layer.js"></script>
<style type="text/css">
	body {
		background-color: #2B2B2B;
	}

	.codeDiv {
		position: relative;
		width: 250px;
		margin: auto;
		overflow: hidden;
	}

	input[name=code] {
		text-align: left;
	}

	.codeImg {
		position: absolute;
		right: 2px;
		top: 2px;
		height: 39px;
	}
</style>

<body data-controller="accountBindController">

	<div class="wrapper">

		<div class="container">
			<h1>创建用户</h1>
			<form method="post" onSubmit="return change();">
				<input name="mobile" type="number" placeholder="请输入您的手机号码">

<!-- 
				<input id="sendSMS" style="margin: 8px 10px;" onClick="sends()" class="weui_btn weui_btn_mini weui_btn_default" type="button" value="发送验证短信" /> -->

				<!-- <div class="codeDiv" style="">
					<input name="code" type="text" placeholder="验证码">
					<img src="/captcha/{tmp}" class="codeImg" alt="" onclick="this.src='/captcha/{tmp}?t='+Date.parse(new Date())" />
				</div> -->
				<!-- <input name="vcode" type="number" placeholder="您收到的短信验证码"> -->

				<input id="password" name="password" type="password" placeholder="请输入您的密码">
				<input id="confirm_password" name="confirm_password" type="password" placeholder="请确认您的密码" onblur="confirmPassword()">
				<br />


				<div> 推荐人ID(必填)</div>
				<?php if (!empty($tid)) { ?>

					<input name="tid" type="text" value="<?php echo $tid; ?>">
				<?php } else { ?>
					<input name="tid" type="text" placeholder="请输入推荐人ID">
				<?php }  ?>

				<button type="submit">确认注册</button>
				<p class="message"><a href="/user-login">使用已有的账号</a> &nbsp &nbsp&nbsp&nbsp&nbsp&nbsp<a id="forgetPassword">找回密码</a></p>
			</form>
		</div>

		<ul class="bg-bubbles">
			<li></li>
			<li></li>
			<li></li>
			<li></li>
			<li></li>
			<li></li>
			<li></li>
			<li></li>
			<li></li>
			<li></li>
		</ul>

	</div>

	<script type="text/javascript" src="/login/js/jquery-2.1.1.min.js"></script>

	<script type="text/javascript">
		var curCount = 60 ; //当前剩余秒数
		var count = 60; //间隔函数，1秒执行
		var InterValObj; //定时器
		// setInterval(function(){ alert("Hello"); }, 3000);

		function msg(text) {
			layer.open({
				content: text,
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
		}

		function sends() {
			var tel = $("input[name=mobile]").val();

			if (tel == null || tel == undefined || tel == '') {
				msg('手机号不能为空!');
				return false;
			}
			if (!(/^1[3|4|5|7|8][0-9]\d{4,8}$/.test(tel))) {
				msg("请输入正确的手机号格式");
				return false;
			}

			$.ajax({
				url: 'http://gzmxkj.com/api/verify-code',
				data: {
					phone: tel
				},
				method: 'post',
				success:res => {
					if(res.status == 200) {
						$("#sendSMS").attr("disabled", true); //启用按钮
						InterValObj = setInterval(function(){SetRemainTime()}, 1000)
					}
					alert(res.msg)
				}

			})
			
			// if (code == null || code == undefined || code == '') {
			// 	msg('验证码不能为空!');
			// 	return false;
			// }
		}

		//timer处理函数
		function SetRemainTime() {
			if (curCount == 0) {
				window.clearInterval(InterValObj); //停止计时器
				$("#sendSMS").attr("disabled", false);//启用按钮
				$("#sendSMS").val("重新发送验证码");
				curCount = 60;
			} else {
				curCount--;
				$("#sendSMS").val("重新发送(" + curCount + ")");
			}
		}

		function confirmPassword() {
			var password = $("#password").val(); //启用按钮
			var confirmPassword = $("#confirm_password").val();
			if (password != confirmPassword) {
				alert('两次输入密码不一致')
			}
		}

		function change() {
			var mobile = $('input[name=mobile]').val();
			var vcode = $('input[name=vcode]').val();
			var password = $('input[name=password]').val();
			var tid = $('input[name=tid]').val();
			if (!(/^1[3|4|5|7|8][0-9]\d{4,8}$/.test(mobile))) {
				msg("账号必须是手机格式");
				return false;
			}
			if (mobile == null || mobile == undefined || mobile == '') {
				msg("手机号不能为空");
				return false;
			}
			if (password == null || password == undefined || password == '') {
				msg("密码不能为空");
				return false;
			}
			if (tid == null || tid == undefined || tid == '') {
				msg("推荐人不能为空");
				return false;
			}
			// if (vcode == null || vcode == undefined || vcode == '') {
			// 	msg("验证码不能为空");
			// 	return false;
			// }
		}

		$('#forgetPassword').click(function() {
			alert('请联系客服')
		})
	</script>

	<?php include_once 'footer.php'; ?>